package com.diecolor.power.controller;

import com.diecolor.power.dao.SystemMenuMapper;
import com.diecolor.power.domain.ResultBean;
import com.diecolor.power.domain.Role;
import com.diecolor.power.domain.SystemMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("admin/menu")
public class SystemMenuController {
    @Autowired
    private SystemMenuMapper mapper;

    @RequestMapping("list")
    public String list(){
        return "admin/system_menu/list";
    }

    @RequestMapping("tree")
    @ResponseBody
    public Object findall()
    {

       List<SystemMenu> list=mapper.selectall();
        return list;
    }


    @PostMapping("save")
    @ResponseBody
    public Object save(SystemMenu record)
    {
        ResultBean bean=new ResultBean();
        try {

            int rows=mapper.insertSelective(record);
            if (rows>=1)
            {
                bean.setObject(record);
            }
            else{
                bean.setCode(10001);
                bean.setMsg("保存失败");
            }
        }catch (Exception e)
        {
            e.printStackTrace();
            bean.setCode(10002);
            bean.setMsg("保存异常");
        }
        return  bean;
    }
}
